import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:series_play/comm/base/base_state.dart';
import 'package:series_play/comm/ext/context_ext.dart';
import 'package:series_play/generated/assets.dart';
import 'package:series_play/widget/app_image.dart';
import 'package:series_play/widget/app_text.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends BaseState<SettingPage> {
  bool isOpenMessageNotify = false;

  @override
  Widget buildPage(BuildContext context) {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16).w,
      child: Column(
        children: [
          normalItem(
            context.tr.messageNotify,
            () {},
            action: Transform.translate(
              offset: Offset(16.w, 0),
              child: Transform.scale(
                scale: 0.6,
                child: Switch(
                  value: isOpenMessageNotify,
                  onChanged: (value) {
                    setState(() {
                      isOpenMessageNotify = value;
                    });
                  },
                ),
              ),
            ),
          ),
          12.verticalSpace,
          normalItem(context.tr.privacyAgreement, () {}),
          12.verticalSpace,
          normalItem(context.tr.userAgreement, () {}),
          12.verticalSpace,
          normalItem(context.tr.clearCache, () {}),
          12.verticalSpace,
          normalItem(context.tr.logout, () {}),
        ],
      ),
    );
  }

  Widget normalItem(String name, VoidCallback onTap, {Widget? action}) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16).w,
        height: 44.w,
        decoration: BoxDecoration(
          color: const Color(0xFF292B34).withValues(alpha: 0.5),
          borderRadius: BorderRadius.circular(6).r,
        ),
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            AppText.title(name, color: Colors.white),
            action ??
                AppImage(Assets.imagesIcArrowRight, width: 14, height: 24),
          ],
        ),
      ),
    );
  }

  @override
  bool showDefaultBackground() {
    return true;
  }

  @override
  String getTitle() {
    return context.tr.setting;
  }
}
